﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System.Runtime.Serialization;
using System;
using System.Threading;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Text;
using BrainTechLLC.ThreadSafeObjects;
using System.ComponentModel;
using System.IO;
using Mud.EmlenMudMain;
using System.Diagnostics;

namespace BrainTechLLC
{
    public static class Rand
    {
        public static Random Rnd = new Random();
        public static int RandIntBetween(int x, int y)
        {
            return Rnd.Next(x, y);
        }
    }

    [Serializable]
    public class RoomData : GameThingBaseClass
    {
        public GameLocation CreateGameLocation(int x, int y, int z)
        {
            LocationInt location = new LocationInt(x, y, z);

            GameLocation result = new GameLocation()
            {
                XYZ = location,
                AreaName = this.areastring,
                RoomDescription = desc,
                Name = new NameAndDescription() { Name = this.Name.Name, OneLineDescription = this.Name.Name, Description = this.RoomDescription, FriendlyUniqueName = this.vnum.ToString() },
                RoomFlags = this.rmflags,
                SectorType = this.sectortyp,
                Vnum = this.VnumRoom
            };

            if (this.travelpts > 0)
            {
                result.AddOrSetProperty("TravelPoints", this.travelpts);
            }

            if (this.exits != null && this.exits.Length > 0)
            {
                for (int n = 0; n < this.exits.Length; n++)
                {
                    ExitData exit = this.exits[n] as ExitData;

                    if (exit != null)
                    {
                        GeneralDirection dir = (GeneralDirection)n;
                        LocationInt copy = new LocationInt(location);
                        copy = copy.Add(dir.GetDirectionVector());
                        var edge = exit.ToLocationEdge(dir, copy.x, copy.y, copy.z);                        
                        result.Edges[n] = edge;
                    }
                }
            }

            if (this.extraDescriptions != null)
            {
                foreach (ExtraDescriptionData extra in this.extraDescriptions)
                {
                    result.ExtraDescriptions.Add(new NameAndDescription() { Description = extra.Description, Keywords = extra.Keyword });
                }
            }

            if (!string.IsNullOrEmpty(this.move_message))
            {
                if (!this.move_message.StartsWith("None") && this.move_message != "(null)")
                {
                    result.AddOrSetProperty("MoveMessage", this.move_message);
                    result.AddOrSetProperty("MoveDirection", this.mvDir);
                }
            }

            if (this.moreRoomDetailsInternal != null)
            {
                result.Coins = this.moreRoomDetailsInternal.CopperCoins + (this.moreRoomDetailsInternal.GoldCoins * 100);

                if (this.moreRoomDetailsInternal.LightingAmount != 0)
                    result.AddOrSetProperty("LightingAmount", this.moreRoomDetailsInternal.LightingAmount);
            }

            result.Register();

            if (this.resets != null)
            {
                foreach (ResetData reset in this.resets)
                {
                    Reset r = reset.ToReset();
                    r.InRoomVnum = this.vnum;
                    r.GameLocationID = result.AssociatedID;
                    result.Resets.Add(r.AssociatedID, r.AssociatedID);
                }
            }

            return result;
        }

        public RoomData() { }

        /// <summary>
        /// These exits are the only structure that is "pseudo-persistent"
        /// ExitData (and doors) will retain their state over reboot, but
        /// will also be modified throughout gameplay (opening/closing/etc)
        /// </summary>
        private IExitData[] exits = new ExitData[(int)GeneralDirection.Max];

        public IExitData[] Exits
        {
            get
            {
                if (exits == null) exits = new ExitData[(int)GeneralDirection.Max];
                return (ExitData[])exits;
            }
            set
            {
                if (exits == null) exits = new ExitData[(int)GeneralDirection.Max];
                exits = value;
            }
        }

        private string areastring = string.Empty;

        public string Areastring
        {
            get { return areastring; }
            set { areastring = value; }
        }

        /// <summary>
        /// You can always call room[GeneralDirection.east] to get the ExitData
        /// for the east exit
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        public ExitData this[GeneralDirection dir]
        {
            get
            {
                return (ExitData)Exits[(int)dir];
            }
        }

        [NonSerialized]
        private AreaData areaInternal = null;

        public AreaData AreaInternal
        {
            get { return areaInternal; }
        }

        public AreaData area
        {
            set
            {
                areaInternal = value;
                areastring = (value == null) ? string.Empty : value.ShortName;
            }
            get
            {
                if (areaInternal == null)
                {
                    //for (int i = 0; i < WorldTemplates.AllAreas.Count; i++)
                    //{
                    //    AreaData ad = (AreaData)WorldTemplates.AllAreas[i];

                    //    if (ad.HasSameNameAs(areastring) == true)
                    //    {
                    //        areaInternal = ad;
                    //        break;
                    //    }
                    //}
                }
                return areaInternal;
            }
        }

        private string desc = "";

        public string RoomDescription
        {
            get { return desc; }
            set { desc = value; }
        }
        /// <summary>
        /// Resets that exist in the currentRoom (as an array of ResetData)
        /// </summary>
        private List<ResetData> resets = new List<ResetData>();

        public List<ResetData> Resets
        {
            get
            {
                if (resets == null) { resets = new List<ResetData>(); }
                return resets;
            }
            set { resets = value; }
        }

        private List<ExtraDescriptionData> extraDescriptions = new List<ExtraDescriptionData>();
        /// <summary>
        /// Extra descriptions in currentRoom
        /// </summary>
        public List<ExtraDescriptionData> ExtraRoomDescriptions
        {
            get
            {
                if (extraDescriptions == null) { extraDescriptions = new List<ExtraDescriptionData>(); }
                return extraDescriptions;
            }
            set { extraDescriptions = value; }
        }

        private int vnum = 0;			/* The currentRoom's vnum */

        /// <summary>
        /// The room's VNUM.  Careful with setting it.  There are no checks here
        /// (yet)
        /// </summary>
        public int VnumRoom
        {
            get { return vnum; }
            set { vnum = value; }
        }

        private RoomFlags rmflags = RoomFlags.NONE;

        public RoomFlags RoomFlagsSet
        {
            get { return rmflags; }
            set { rmflags = value; }
        }
        private int travelpts = 0;			/* Travel points in this currentRoom */

        public int TravelPoints
        {
            get { return travelpts; }
            set { travelpts = value; }
        }

        private SectorType sectortyp = SectorType.NONE;		/* The type of sector this currentRoom is */

        public SectorType SectorTypeSet
        {
            get { return sectortyp; }
            set { sectortyp = value; }
        }

        [NonSerialized]
        private IDynamicRoomDetails moreRoomDetailsInternal = null;

        public IDynamicRoomDetails MoreRoomDetailsInternal
        {
            get { return moreRoomDetailsInternal; }
        }


        public List<CharacterData> characters
        {
            get
            {
                if (moreRoomDetailsInternal == null) moreRoomDetailsInternal = new DynamicRoomDetails();
                return moreRoomDetailsInternal.CharactersInRoom;
            }
        }

        /// <summary>
        /// "MoreRoomInfo" holds the dynamic data in the currentRoom that changes
        /// via gameplay, etc.  The RoomData structure itself primarily
        /// holds persistent data, and therefore it qualifies as a member
        /// of the WorldTemplates class
        /// </summary>
        public IDynamicRoomDetails MoreRoomInfo
        {
            get
            {
                if (moreRoomDetailsInternal == null) { moreRoomDetailsInternal = new DynamicRoomDetails(); }
                return moreRoomDetailsInternal;
            }
            set
            {
                moreRoomDetailsInternal = (IDynamicRoomDetails)value;
            }
        }

        private int roomImg = 0;		/* NYI */

        public int RoomImage
        {
            get { return roomImg; }
            set { roomImg = value; }
        }

        private GeneralDirection mvDir;	/* Moving direction for 'currents' */

        public GeneralDirection AutoMoveDirection
        {
            get { return mvDir; }
            set { mvDir = value; }
        }
        private string move_message;		/* moving message for 'currents' */

        public string Move_message
        {
            get { return move_message; }
            set { move_message = value; }
        }

        public bool IsRoomFlagSet(RoomFlags rf) { return ((rmflags & rf) != 0); }
        public bool Indoors
        {
            get
            {
                return ((rmflags & RoomFlags.INDOORS) != 0);
            }
            set
            {
                if (value == true) rmflags |= RoomFlags.INDOORS;
                else rmflags &= (~RoomFlags.INDOORS);
            }
        }
        public bool IsDark()
        {
            if (MoreRoomInfo.LightingAmount > 0) return false;
            if (IsRoomFlagSet(RoomFlags.DARK)) return true;
            if (IsRoomFlagSet(RoomFlags.INDOORS)) return false;
            if (sectortyp == SectorType.INSIDE) return false;
            // TODO
            //if (DynamicWorld.WeatherInfo.Sunlight == TimeOfDayType.SUN_RISE ||
            //  DynamicWorld.WeatherInfo.Sunlight == TimeOfDayType.SUN_LIGHT ||
            //  DynamicWorld.WeatherInfo.Sunlight == TimeOfDayType.SUN_SET) return false;
            return true;
        }

        public bool HasCharacters
        {
            get
            {
                if (moreRoomDetailsInternal == null) return false;
                return (moreRoomDetailsInternal.CharactersInRoom.Count > 0);
            }
        }

        public CharacterData FindCharacterInRoom(string szKeywordOrName)
        {
            if (moreRoomDetailsInternal == null) return null;
            if (moreRoomDetailsInternal.CharactersInRoom == null) return null;
            for (int i = 0; i < moreRoomDetailsInternal.CharactersInRoom.Count; i++)
            {
                CharacterData chr = (CharacterData)moreRoomDetailsInternal.CharactersInRoom[i];
                if (chr.IsPlayer)
                {
                    // Search race names?
                }
                if (chr.IsMob)
                {
                    if (!string.IsNullOrEmpty(chr.mobPrototype.Mobprototypename))
                    {
                        string[] rgKeywords = chr.mobPrototype.Mobprototypename.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        if (rgKeywords != null)
                        {
                            for (int j = 0; j < rgKeywords.Length; j++)
                            {
                                if (rgKeywords[j].Equals(szKeywordOrName, StringComparison.OrdinalIgnoreCase) == true)
                                    return chr;
                            }
                        }
                    }
                }

            }
            return null;
        }

        //public CharacterData FindCharacterInRoom(string comparable)
        //{
        //    if (moreRoomDetailsInternal == null) return null;
        //    if (moreRoomDetailsInternal.CharactersInRoom == null) return null;
        //    for (int i = 0; i < moreRoomDetailsInternal.CharactersInRoom.Count; i++)
        //    {
        //        CharacterData chr = (CharacterData)moreRoomDetailsInternal.CharactersInRoom[i];
        //        if (chr.HasSameNameAs(comparable)) return chr;
        //    }
        //    return null;
        //}

        public StringBuilder GetReasonWhyCharacterCantSeeInRoom(CharacterData chrLooker)
        {
            StringBuilder sb = new StringBuilder(1024);
            if (chrLooker.CanSee() == false)
                sb.Append("You are blind!");
            else if (IsDark() == true && chrLooker.HasAbilityToSeeInDark() == false)
                sb.Append("{y}It is pitch black ... ");
            else
            {
                sb.Append("{g}It's hard to see through this fog.");
            }

            return sb;
        }

        public ExitData GetOtherRoomIncomingExitDataForThisRoomOutgoingDirection(GeneralDirection dir)
        {
            if (exits == null) return null;
            ExitData ex = (ExitData)exits[(int)dir];
            if (ex == null) return null;
            return (ExitData)ex.GetIncomingExitDataForDirection(dir);
        }

        public StringBuilder HowRoomLooksTo(CharacterData chrLooker)
        {
            StringBuilder sb = new StringBuilder(1024);
            // TODO
            //if (!chrLooker.CanSee(this))
            //{
            //    return GetReasonWhyCharacterCantSeeInRoom(chrLooker);
            //}

            sb.Append("{W}" + Name);
            if (chrLooker.AutoExit)
            {
                int nExits = 0;
                ExitData ex;
                for (int i = 0; i < (int)GeneralDirection.Max; i++)
                {
                    ex = (ExitData)exits[i];
                    if (ex == null) continue;
                    if (chrLooker.CanSee(ex) == false) continue;
                    if (nExits == 0) { sb.Append(" {G}["); }
                    else { sb.Append(", "); }
                    sb.Append(chrLooker.GetShortExitNameInDirection(this, (GeneralDirection)i));
                    nExits++;
                }
                if (nExits > 0) sb.Append("]");
            }
            sb.Append("{N}\n\r{w}" + desc);
            if (moreRoomDetailsInternal != null)
            {
                int k = 0;
                for (int i = 0; i < moreRoomDetailsInternal.CharactersInRoom.Count; i++)
                {
                    CharacterData chVict = moreRoomDetailsInternal.CharactersInRoom[i];
                    if (chrLooker == chVict) continue;
                    if (chrLooker.CanSee(chVict) == true)
                    {
                        k++;
                        sb.Append("{W}[" + k.ToString() + "]{w} " + chrLooker.ViewAsAppearsInRoom(chVict));
                    }
                }
            }

            return sb;
        }


        // what exactly does this do?? what funky currentRoom name formatting
        // is there with the ;?
        //string show_room_name (CharacterData  chr, string roomname)
        //{
        //  static char rbuf[328];
        //  int sl = 0;
        //  string t;
        //  rbuf[0] = '\0';
        //  if (!roomname)
        //    {
        //      strcpy (rbuf, "Error!  NULL roomname!");
        //      return rbuf;
        //    }
        //  if (LEVEL (chr) < 100)
        //    {
        //      for (t = roomname; *t != '\0'; t++)
        //	{
        //	  if (*t == ';')
        //	    {
        //	      rbuf[0] = '\0';
        //	      sl = 0;
        //	      continue;
        //	    }
        //	  rbuf[sl] = *t;
        //	  sl++;
        //	}
        //      rbuf[sl] = '\0';
        //    }
        //  else
        //    {
        //      bool found_semi = FALSE;
        //      for (t = roomname; *t != '\0'; t++)
        //	{
        //	  if (*t == ';')
        //	    {
        //	      found_semi = TRUE;
        //	      break;
        //	    }
        //	}
        //      if (found_semi)
        //	{
        //	  strcpy (rbuf, "\x1B[34;1m(");
        //	  sl = (int) strlen (rbuf);
        //	}
        //      for (t = roomname; *t != '\0'; t++)
        //	{
        //	  if (*t == ';')
        //	    {
        //	      rbuf[sl] = '\0';
        //	      strcat (rbuf, ") \x1B[37;1m");
        //	      sl = (int) strlen (rbuf);
        //	      continue;
        //	    }
        //	  rbuf[sl] = *t;
        //	  sl++;
        //	}
        //      rbuf[sl] = '\0';
        //    }
        //
        //  return rbuf;
        //}

        //}

        //         /*if (IS_JAVA(chr)) java_cc(chr,6);*/
        //         if (!IS_JAVA(chr) || arg1[0]=='\0') {
        //            ansi_color (GREY, chr);
        //            ansi_color (BOLD, chr);
        //            send_to_char (show_room_name (chr, chr->inRoom->name), chr);
        //         } else
        //         {
        //            char bf[STD_LENGTH];
        //            sprintf(bf, "%c%c",(char)23,(char)200);
        //            write_to_buffer(chr->description,bf,0);
        //            write_to_buffer(chr->description,strip_ansi_codes(show_room_name (chr, chr->inRoom->name)), 0);
        //            write_to_buffer(chr->description,"\n\r",0);
        //         }
        //         if (!IS_JAVA(chr)) {
        //            if (IS_SET (chr->inRoom->rmflags, ROOM_INDOORS))
        //               send_to_char (" \x1B[37;0m[\x1B[33mIndoors\x1B[37m]", chr);
        //            else if (weatherInfo.sunlight == SUN_LIGHT ||
        //               weatherInfo.sunlight == SUN_RISE ||
        //               weatherInfo.sunlight == SUN_SET)
        //            {
        //               if (weatherInfo.sky == SKY_RAINING && chr->inRoom->sectortyp == SECT_DESERT)
        //                  send_to_char (" \x1B[37;0m[\x1B[30;1mStormy\x1B[37;0m]", chr);
        //               else if (weatherInfo.sky == SKY_RAINING)
        //                  send_to_char (" \x1B[37;0m[\x1B[30;1mRaining\x1B[37;0m]", chr);
        //               else if (weatherInfo.sky == SKY_FOGGY)
        //                  send_to_char (" \x1B[37;0m[\x1B[30;1mFoggy\x1B[37;0m]", chr);
        //               else if (weatherInfo.sky == SKY_LIGHTNING)
        //                  send_to_char (" \x1B[37;0m[\x1B[33;1mLightning\x1B[37;0m]", chr);
        //               else if (weatherInfo.sky == SKY_CLOUDY)
        //                  send_to_char (" \x1B[37;0m[Overcast]", chr);
        //               else if (chr->inRoom->shade)
        //                  send_to_char (" \x1B[37;0m[\x1B[30;1mShaded\x1B[37;0m]", chr);
        //               else
        //               {
        //                  if (weatherInfo.sunlight == SUN_LIGHT)
        //                     send_to_char (" \x1B[37;0m[\x1B[33;1mSunrise\x1B[37;0m]", chr);
        //                  if (weatherInfo.sunlight == SUN_RISE)
        //                     send_to_char (" \x1B[37;0m[\x1B[33;1mSunny\x1B[37;0m]", chr);
        //                  if (weatherInfo.sunlight == SUN_SET)
        //                     send_to_char (" \x1B[37;0m[\x1B[33;1mSunset\x1B[37;0m]", chr);
        //               }
        //            }
        //            else if (weatherInfo.sunlight == SUN_DARK ||
        //               weatherInfo.sunlight == MOON_RISE ||
        //               weatherInfo.sunlight == MOON_SET)
        //            {
        //               if (weatherInfo.sky == SKY_LIGHTNING)
        //                  send_to_char (" \x1B[37;0m[\x1B[33;1mLightning\x1B[37;0m/\x1B[30;1mNight\x1B[37;0m]", chr);
        //               else if (weatherInfo.sky == SKY_RAINING)
        //                  send_to_char (" \x1B[37;0m[\x1B[30;1mRaining/Night\x1B[37;0m]", chr);
        //               else
        //                  send_to_char (" \x1B[37;0m[\x1B[30;1mNight\x1B[37;0m]", chr);
        //            }

        //         } /* End !is_java */
        //         if (!IS_JAVA(chr) || arg1[0]=='\0') {
        //            send_to_char ("\n\r ", chr);
        //            send_to_char ("\x1B[37;0m", chr);
        //         }
        //#ifdef NEW_WORLD
        //         if (check_hills (chr, arg1))
        //         {
        //         }
        //         else if (check_field_d (chr, arg1))
        //         {
        //         }
        //         else if (check_ancientroad (chr, arg1))
        //         {
        //         }
        //         else if (check_earthcave_d (chr, arg1))
        //         {
        //         }
        //         else if (check_lforest_d (chr, arg1))
        //         {
        //         }
        //         else if (check_forest_d (chr, arg1))
        //         {
        //         }
        //         else if (check_ocean_d (chr, arg1))
        //         {
        //         }
        //         else if (IS_SET (chr->inRoom->room_flags_2, ROOM2_RFOREST_D) &&
        //            (!IS_SET (chr->pcdata->act2, PLR_BRIEF) || arg1[0] == '\0'))
        //         {
        //            char rd[STD_LENGTH];
        //            char weather[512];
        //            string t;
        //            sprintf (rd, "%s", rainforest[number_range (0, 6)]);
        //            if (weatherInfo.sky == SKY_CLOUDLESS)
        //            {
        //               sprintf (weather, "  The cloudless sky is barely visible through the dense canopy of branches above.");
        //            }
        //            else if (weatherInfo.sky == SKY_CLOUDY)
        //            {
        //               sprintf (weather, "  A white blanket of mist melds flawlessly into the sky, high above.");
        //            }
        //            else if (weatherInfo.sky == SKY_RAINING)
        //            {
        //               sprintf (weather, "  Fierce torrents of rain cascade down from the branches high above.");
        //            }
        //            else if (weatherInfo.sky == SKY_FOGGY)
        //            {
        //               sprintf (weather, "  A dense fog hangs in the air, making it difficult to see low-lying branches, which constantly brush against you, tearing at your body.");
        //            }
        //            else if (weatherInfo.sky == SKY_LIGHTNING)
        //            {
        //               sprintf (weather, "  The dense canopy overhead is lit with brief, spectacular flashes of lightning.");
        //            }
        //            strcat (rd, weather);
        //            if (chr->inRoom->description && chr->inRoom->description[0] != '\0')
        //            {
        //               strcat (rd, "  ");
        //               strcat (rd, chr->inRoom->description);
        //            }
        //            for (t = rd; *t != '\0'; t++)
        //               if (*t == '\n')
        //                  *t = '\0';
        //            currentActionsAndBehavior (rd, chr, NULL, NULL, TO_CHAR);
        //         }
        //         else
        //#endif
        //            if (arg1[0] == '\0'
        //               || (IS_PLAYER (chr) && !IS_SET (chr->pcdata->act2, PLR_BRIEF)))
        //               send_to_char (chr->inRoom->description, chr);
        //         if (IS_PLAYER (chr) && IS_SET (chr->pcdata->act2, PLR_AUTOEXIT))
        //         {
        //            if (!IS_JAVA(chr) || arg1[0]=='\0') {
        //               ansi_color (BOLD, chr);
        //               ansi_color (BLUE, chr);
        //               do_exits (chr, "auto");
        //               ansi_color (NTEXT, chr);
        //            } else {
        //               do_exits (chr, "auto");
        //            }
        //         }
        //         if (chr->inRoom->MoreRoomInfo->contents)
        //         {
        //            ansi_color (NTEXT, chr);
        //            ansi_color (CYAN, chr);
        //         }
        //         if (chr->inRoom->MoreRoomInfo->gold > 0 || chr->inRoom->MoreRoomInfo->copper > 0)
        //         {
        //            char bufff[STD_LENGTH];
        //            if (chr->inRoom->MoreRoomInfo->gold > 0 && chr->inRoom->MoreRoomInfo->copper == 0)
        //            {
        //               sprintf (bufff, "\x1B[37;0mThere %s %d \x1B[33;1mgold\x1B[37;0m coin%s here.\x1B[37;0m\n\r",
        //                  (chr->inRoom->MoreRoomInfo->gold > 1 ? "are" : "is"), chr->inRoom->MoreRoomInfo->gold,
        //                  (chr->inRoom->MoreRoomInfo->gold > 1 ? "s" : ""));
        //            }
        //            else if (chr->inRoom->MoreRoomInfo->gold == 0 && chr->inRoom->MoreRoomInfo->copper > 0)
        //            {
        //               sprintf (bufff, "\x1B[37;0mThere %s %d \x1B[33;0mcopper\x1B[37;0m coin%s here.\x1B[37;0m\n\r",
        //                  (chr->inRoom->MoreRoomInfo->copper > 1 ? "are" : "is"), chr->inRoom->MoreRoomInfo->copper,
        //                  (chr->inRoom->MoreRoomInfo->copper > 1 ? "s" : ""));
        //            }
        //            else if (chr->inRoom->MoreRoomInfo->gold > 0 && chr->inRoom->MoreRoomInfo->copper > 0)
        //            {
        //               sprintf (bufff, "\x1B[37;0mThere %s %d \x1B[33;1mgold\x1B[37;0m coin%s and %d \x1B[33;0mcopper\x1B[37;0m coin%s here.\x1B[37;0m\n\r",
        //                  (chr->inRoom->MoreRoomInfo->gold > 1 ? "are" : "is"), chr->inRoom->MoreRoomInfo->gold,
        //                  (chr->inRoom->MoreRoomInfo->gold > 1 ? "s" : ""), chr->inRoom->MoreRoomInfo->copper,
        //                  (chr->inRoom->MoreRoomInfo->copper > 1 ? "s" : ""));
        //            }
        //            send_to_char (bufff, chr);
        //         }
        //         if (chr->inRoom->linkage)
        //         {
        //            ROOM_DATA *rrs;
        //            for (rrs = chr->inRoom->linkage; rrs != NULL; rrs = rrs->linkage)
        //            {
        //               if (!rrs->MoreRoomInfo)
        //                  continue;
        //               if (iir && iir == rrs)
        //                  continue;
        //               if (!rrs->MoreRoomInfo->obj_description || rrs->MoreRoomInfo->obj_description[0] == '\0')
        //                  continue;
        //               send_to_char (rrs->MoreRoomInfo->obj_description, chr);
        //            }
        //         }
        //         java_clear_mob_window(chr);
        //         show_list_to_char (chr->inRoom->MoreRoomInfo->contents, chr, FALSE, FALSE);
        //         show_char_to_char (chr->inRoom->MoreRoomInfo->people, chr);
        //         if (!IS_JAVA(chr) || arg1[0]=='\0' || (chr->inRoom && chr->inRoom->MoreRoomInfo && 
        //            (chr->inRoom->MoreRoomInfo->contents || chr->inRoom->MoreRoomInfo->people!=chr ||
        //            chr->inRoom->MoreRoomInfo->people->next_in_room))) {
        //               send_to_char ("\x1B[37;0m", chr);
        //         }
        //         return;
        //      }
        //      if (!str_cmp (arg1, "i") || !str_cmp (arg1, "in") || !str_cmp (arg1, "inside"))
        //      {
        //         /* 'look in' */
        //         if (arg2[0] == '\0')
        //         {
        //            send_to_char ("Look in what?\n\r", chr);
        //            return;
        //         }
        //         if ((obj = get_obj_here (chr, arg2, SEARCH_INV_FIRST)) == NULL)
        //         {
        //            send_to_char ("You do not see that here.\n\r", chr);
        //            return;
        //         }
        //         switch (obj->pIndexData->item_type)
        //         {
        //         default:
        //            send_to_char ("That is not a container.\n\r", chr);
        //            break;
        //         case ITEM_LIGHT:
        //            {
        //               I_LIGHT *lght = (I_LIGHT *) obj->MoreRoomInfo;
        //               if (obj->carried_by && obj->wear_loc == WEAR_NONE)
        //                  send_to_char ("(In Inventory) ", chr);
        //               if (obj->carried_by && obj->wear_loc != WEAR_NONE)
        //                  send_to_char ("(Equipped) ", chr);
        //               if (!obj->carried_by)
        //                  send_to_char ("(On the Ground) ", chr);
        //               if (lght->max_light != 0)
        //               {
        //                  int percent = PERCENTAGE (lght->light_now, lght->max_light);
        //                  if (lght->light_now <= 0)
        //                  {
        //                     send_to_char ("It is empty.\n\r", chr);
        //                     break;
        //                  }
        //                  else
        //                  {
        //                     sprintf (buf, "It's %s of fuel.\n\r", percent < 10 ? "almost empty" : percent < 40 ? "less than half full" : percent < 60 ? "half full" : percent < 90 ? "MoreRoomInfo than half" : "full"); 
        //                     send_to_char (buf, chr);
        //                  }
        //               }
        //               else
        //                  send_to_char ("It contains nothing.\n\r", chr);
        //               break;
        //            }
        //         case ITEM_DRINK_CON:
        //            {
        //               I_DRINK *dr = (I_DRINK *) obj->MoreRoomInfo;
        //               if (obj->carried_by && obj->wear_loc == WEAR_NONE)
        //                  send_to_char ("(In Inventory) ", chr);
        //               if (obj->carried_by && obj->wear_loc != WEAR_NONE)
        //                  send_to_char ("(Equipped) ", chr);
        //               if (!obj->carried_by)
        //                  send_to_char ("(On the Ground) ", chr);
        //               if (dr->liquid_now <= 0)
        //               {
        //                  send_to_char ("It is empty.\n\r", chr);
        //                  break;
        //               }
        //               else
        //               {
        //                  int percent = PERCENTAGE (dr->liquid_now, dr->max_liquid);
        //                  if (dr->liquid_type == -1)
        //                  {
        //                     if (obj->carried_by && obj->wear_loc == WEAR_NONE)
        //                        send_to_char ("(In Inventory) ", chr);
        //                     if (obj->carried_by && obj->wear_loc != WEAR_NONE)
        //                        send_to_char ("(Equipped) ", chr);
        //                     if (!obj->carried_by)
        //                        send_to_char ("(On the Ground) ", chr);
        //                     sprintf (buf, "It's %s of lamp oil.\n\r", percent < 10 ? "almost empty" : percent < 40 ? "less than half full" : percent < 60 ? "half full" : percent < 70 ? "MoreRoomInfo than half full" : "full");
        //                  }
        //                  else
        //                  {
        //                     if (obj->carried_by && obj->wear_loc == WEAR_NONE)
        //                        send_to_char ("(In Inventory) ", chr);
        //                     if (obj->carried_by && obj->wear_loc != WEAR_NONE)
        //                        send_to_char ("(Equipped) ", chr);
        //                     if (!obj->carried_by)
        //                        send_to_char ("(On the Ground) ", chr);
        //                     sprintf (buf, "It's %s of a %s liquid.\n\r", percent < 10 ? "almost empty" : percent < 40 ? "less than half full" : percent < 60 ? "half full" : percent < 70 ? "MoreRoomInfo than half full" : "full", (dr->liquid_type > 12 ? "ERROR!!" : liq_table[dr->liquid_type].liq_color));
        //                  }
        //                  send_to_char (buf, chr);
        //               }
        //               break;
        //            }
        //         case ITEM_CONTAINER:
        //         case ITEM_CORPSE_NPC:
        //         case ITEM_CORPSE_PC:
        //            {
        //               I_CONTAINER *con = (I_CONTAINER *) obj->MoreRoomInfo;
        //               if (obj->carried_by && obj->wear_loc == WEAR_NONE)
        //                  send_to_char ("(In Inventory) ", chr);
        //               if (obj->carried_by && obj->wear_loc != WEAR_NONE)
        //                  send_to_char ("(Equipped) ", chr);
        //               if (!obj->carried_by)
        //                  send_to_char ("(On the Ground) ", chr);
        //               if (IS_SET (con->flags, CONT_CLOSED))
        //               {
        //                  send_to_char ("It is closed.\n\r", chr);
        //                  break;
        //               }
        //               if (LEVEL (chr) > 109)
        //               {
        //                  print_reasons (chr, obj);
        //               }
        //               currentActionsAndBehavior ("$p\x1B[0m contains:", chr, obj, NULL, TO_CHAR);
        //               if (con->money > 0)
        //               {
        //                  char ttu[STD_LENGTH];
        //                  sprintf (ttu, "%s coins.\n\r", name_amount (con->money));
        //                  send_to_char (ttu, chr);
        //               }
        //               show_list_to_char (obj->contains, chr, TRUE, TRUE);
        //               break;
        //            }
        //         }
        //         return;
        //      }
        //      if ((victim = get_char_room (chr, arg1)) != NULL)
        //      {
        //         show_char_to_char_1 (victim, chr);
        //         if (IS_MOB (victim) && (FIGHTING (victim) == NULL) &&
        //            IS_SET (victim->currentActionsAndBehavior, ACT_ATTITUDE) && can_see (victim, chr) &&
        //            IS_AWAKE (victim))
        //         {
        //            do_say (victim, "How dare you look at me! You will die!");
        //            multi_hit (victim, chr, TYPE_UNDEFINED);
        //         }
        //         return;
        //      }
        //      count = number_argy (arg1, arg2);
        //      number = 0;
        //      for (obj = chr->carryingObjects; obj && obj != NULL; obj = obj->next_content)
        //      {
        //         if (can_see_obj (chr, obj))
        //         {
        //            if (is_name (arg2, obj->pIndexData->name))
        //            {
        //               if (++number != count)
        //                  continue;
        //               send_to_char ("(This object is in your inventory)\n\r", chr);
        //               pdesc = get_extra_descr (arg1, obj->pIndexData->extraDescriptions);
        //               if (!pdesc && obj->pIndexData->extraDescriptions && (!str_cmp(obj->pIndexData->name,arg1) ||
        //                  !str_cmp(obj->pIndexData->name,arg2)))
        //                  pdesc=obj->pIndexData->extraDescriptions->description;

        //               if (pdesc != NULL)
        //               {
        //                  if (IS_JAVA(chr)) 
        //                     page_to_char (wordwrap(pdesc,79), chr);
        //                  else
        //                     page_to_char (wordwrap(pdesc,79), chr);
        //               }
        //               if (obj->pIndexData->made_of>0) {
        //                  if (IS_JAVA(chr))
        //                     send_to_char(wordwrap(materials[obj->pIndexData->made_of-1].description,79),chr);
        //                  else
        //                     send_to_char(wordwrap(materials[obj->pIndexData->made_of-1].description,79),chr);
        //                  send_to_char("\n\r",chr);
        //               } else
        //                  if (pdesc==NULL)
        //                     currentActionsAndBehavior ("You see nothing special about $p.", chr, obj, chr, TO_CHAR);
        //               return;
        //            }
        //         }
        //      }
        //      for (obj = chr->carryingObjects; obj && obj != NULL; obj = obj->next_content)
        //      {
        //         if (can_see_obj (chr, obj))
        //         {
        //            if (is_approx_name (arg2, obj->pIndexData->name))
        //            {
        //               if (++number != count)
        //                  continue;
        //               send_to_char ("(This object is in your inventory)\n\r", chr);
        //               pdesc = get_extra_descr (arg1, obj->pIndexData->extraDescriptions);
        //               if (pdesc != NULL)
        //               {
        //                  page_to_char (pdesc, chr);
        //                  return;
        //               }
        //               currentActionsAndBehavior ("You see nothing special about $p.", chr, obj, chr, TO_CHAR);
        //               return;
        //            }
        //         }
        //      }
        //      number = 0;
        //      for (obj = chr->inRoom->MoreRoomInfo->contents; obj && obj != NULL; obj = obj->next_content)
        //      {
        //         if (can_see_obj (chr, obj))
        //         {
        //            if (is_name (arg2, obj->pIndexData->name))
        //            {
        //               if (++number != count)
        //                  continue;
        //               send_to_char ("(This object is in the currentRoom)\n\r", chr);
        //               pdesc = get_extra_descr (arg1, obj->pIndexData->extraDescriptions);
        //               if (pdesc != NULL)
        //               {
        //                  page_to_char (pdesc, chr);
        //                  return;
        //               }
        //               currentActionsAndBehavior ("You don't see anything special about $p.", chr, obj, chr, TO_CHAR);
        //               return;
        //            }
        //         }
        //      }
        //      for (obj = chr->inRoom->MoreRoomInfo->contents; obj && obj != NULL; obj = obj->next_content)
        //      {
        //         if (can_see_obj (chr, obj))
        //         {
        //            if (is_approx_name (arg2, obj->pIndexData->name))
        //            {
        //               if (++number != count)
        //                  continue;
        //               send_to_char ("(This object is in the currentRoom)\n\r", chr);
        //               pdesc = get_extra_descr (arg1, obj->pIndexData->extraDescriptions);
        //               if (pdesc != NULL)
        //               {
        //                  page_to_char (pdesc, chr);
        //                  return;
        //               }
        //               currentActionsAndBehavior ("You don't see anything special about $p.", chr, obj, chr, TO_CHAR);
        //               return;
        //            }
        //         }
        //      }
        //      pdesc = NULL;
        //      if (chr->inRoom->MoreRoomInfo)
        //         pdesc = get_extra_descr (arg1, chr->inRoom->MoreRoomInfo->extraDescriptions);
        //      if (pdesc != NULL)
        //      {
        //         page_to_char (pdesc, chr);
        //         return;
        //      }
        //      send_to_char ("You do not see that here.\n\r", chr);
        //      return;
        //lookdirection:
        //      if (!str_cmp (arg1, "n") || !str_cmp (arg1, "north"))
        //         door = 0;
        //      else if (!str_cmp (arg1, "e") || !str_cmp (arg1, "east"))
        //         door = 1;
        //      else if (!str_cmp (arg1, "s") || !str_cmp (arg1, "south"))
        //         door = 2;
        //      else if (!str_cmp (arg1, "w") || !str_cmp (arg1, "west"))
        //         door = 3;
        //      else if (!str_cmp (arg1, "u") || !str_cmp (arg1, "up"))
        //         door = 4;
        //      else if (!str_cmp (arg1, "d") || !str_cmp (arg1, "down"))
        //         door = 5;
        //      else
        //      {
        //         send_to_char ("You can't look that way.\n\r", chr);
        //         return;
        //      }
        //      /* 'look direction' */
        //      if ((pexit = chr->inRoom->exit[door]) == NULL)
        //      {
        //         if (!chr->ced || !chr->ced->scanning)
        //            send_to_char ("You do not see anything in that direction.\n\r", chr);
        //         return;
        //      }
        //      if (!chr->ced || !chr->ced->scanning)
        //      {
        //         if (pexit->d_info && pexit->d_info->str < 0)
        //         {
        //            send_to_char ("There used to be a door there, but now it's just rubble.\n\r",
        //               chr);
        //            goto doscan;
        //         }
        //         if (pexit->d_info && pexit->d_info->description != NULL && pexit->d_info->description[0] != '\0')
        //         {
        //            string t;
        //            char ed[STD_LENGTH];
        //            int ct = 0;
        //            for (t = pexit->d_info->description; *t != '\0' && ct < 20; t++)
        //            {
        //               if (*t != '\n' && *t != '\r')
        //               {
        //                  ed[ct] = *t;
        //                  ct++;
        //               }
        //            }
        //            ed[ct] = '\0';
        //            if (is_number (ed))
        //            {
        //               int lvnum;
        //               ROOM_DATA *lr;
        //               lvnum = atoi (ed);
        //               if ((lr = get_room_index (lvnum)) != NULL)
        //               {
        //                  char ttt[STD_LENGTH];
        //                  send_to_char ("You look and see........\n\r", chr);
        //                  sprintf (ttt, "%d look", lvnum);
        //                  do_at (chr, ttt);
        //               }
        //            }
        //            else
        //               send_to_char (pexit->d_info->description, chr);
        //         }
        //         else
        //            send_to_char ("You do not see anything in that direction.\n\r", chr);
        //         if ((ROOM_DATA *) pexit->to_room == NULL)
        //            return;
        //         if (pexit->d_info && pexit->d_info->keyword != NULL
        //            && pexit->d_info->keyword[0] != '\0'
        //            && pexit->d_info->keyword[0] != ' ')
        //         {
        //         }
        //         /*end if sc->scanning */
        //         if (pexit->d_info && IS_SET (pexit->d_info->exit_info, EX_HIDDEN) && IS_SET (pexit->d_info->exit_info, EX_CLOSED))
        //         {
        //            return;
        //         }
        //         if (!chr->ced || !chr->ced->scanning)
        //         {
        //            if (pexit->d_info && IS_SET (pexit->d_info->exit_info, EX_CLOSED) && pexit->d_info->keyword != NULL && pexit->d_info->keyword[0] != '\0')
        //            {
        //               currentActionsAndBehavior ("The $T\x1B[0m is closed.", chr, NULL, pexit->d_info->keyword, TO_CHAR);
        //               if (!str_cmp ("door", pexit->d_info->keyword) || !str_prefix ("door", pexit->d_info->keyword)
        //                  || !str_suffix ("door", pexit->d_info->keyword))
        //               {
        //                  if (pexit->d_info->str > 50)
        //                     send_to_char ("The door looks impenetrable!\n\r", chr);
        //                  else if (pexit->d_info->str > 40)
        //                     send_to_char ("The door looks very solid!\n\r", chr);
        //                  else if (pexit->d_info->str > 30)
        //                     send_to_char ("The door could hold up pretty well.\n\r", chr);
        //                  else if (pexit->d_info->str > 20)
        //                     send_to_char ("It wouldn't take a big man long to break.\n\r", chr);
        //                  else if (pexit->d_info->str > 10)
        //                     send_to_char ("What could this thing keep out?!\n\r", chr);
        //                  else
        //                     send_to_char ("You call that a door?!?!\n\r", chr);
        //                  return;
        //               }
        //            }
        //            else if (pexit->d_info && IS_SET (pexit->d_info->exit_info, EX_ISDOOR) && pexit->d_info->keyword != NULL && pexit->d_info->keyword[0] != '\0')
        //            {
        //               currentActionsAndBehavior ("The $T\x1B[0m is open.", chr, NULL, pexit->d_info->keyword, TO_CHAR);
        //               currentActionsAndBehavior ("As you peer for signs of life, you find that you cannot make out any\n\rlifeforms due to the limited line of sight behind the open $T.", chr, NULL, pexit->d_info->keyword, TO_CHAR);
        //               return;
        //            }
        //         }
        //         else
        //         {
        //            if (pexit && (ROOM_DATA *) pexit->to_room != NULL)
        //               scan_direction (chr, door);
        //            return;
        //         }
        //      }
        //      /*end if !chr->scanning */
        //doscan:
        //      if ((ROOM_DATA *) pexit->to_room != NULL)
        //         scan_direction (chr, door);
        //      return;
        //}
    }


}
